package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户人群业务相关
 */
@Tag(name = "用户人群管理")
@RestController
@Slf4j
public class UserGroupController {
    @Autowired
    private UserGroupService userGroupService;


    @Operation(summary = "人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")
    public Result<PageResult<UserGroupVO>> pageList(@RequestBody UserGroupQuery  query)
        throws BusinessException{
        log.info("查询参数:{}",query);
        PageResult<UserGroupVO> voPage = userGroupService.pageList(query);
        log.info("返回结果:{}",voPage);
        return new Result<>(voPage);
    }

    @Operation(summary = "保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> save(@RequestBody @Validated UserGroupParam param)
            throws BusinessException {
        userGroupService.save(param);
        return Result.success();
    }

    @Operation(summary = "删除人群数据")
    @PostMapping("/admin/basic/userGroup/delete/{id}")
    public Result<Void> delete(@PathVariable Integer id) throws BusinessException{
        userGroupService.delete(id);
        return Result.success();
    }
}
